<?php
/* @var $this SiteController */
/* @var $model LoginForm */
/* @var $form CActiveForm  */

$this->pageTitle = Yii::app()->name . ' - ' . Yii::t('home', 'login');
$this->breadcrumbs = array(
    Yii::t('home', 'login'),
);

$baseUrl = Yii::app()->request->baseUrl;
$extScript = Yii::app()->clientScript;
$extScript->registerCssFile($baseUrl . '/layout/styles/switchery.min.css');
$extScript->registerScriptFile($baseUrl . '/layout/scripts/transitionize.min.js');
$extScript->registerScriptFile($baseUrl . '/layout/scripts/switchery.min.js');
$extScript->registerScriptFile($baseUrl . '/js/CryptoJS-v3.1.2/rollups/md5.js');
?>

<div id="focus" class="wrapper row100 bgded" style="background-image:url('images/live-demo/background-03.jpg');">
    <div class="overlay">
        <div id="newsletter" class="clear center">
            <h2 class="uppercase font-x3 btmspace-50"><?= Yii::t('login', 'welcome') ?></h2>
            <div class="form">
                <?php
                $form = $this->beginWidget('CActiveForm', array(
                    'id' => 'login-form',
                    'enableClientValidation' => true,
                    'clientOptions' => array(
                        'validateOnSubmit' => true,
                        'afterValidate' => "js:function(form, data, hasError) {
                if (!hasError) {
                    form[0][1].value = CryptoJS.MD5(form[0][1].value);
                    return true;
                }
                return false;
            }"
                    ),
                    'focus' => array($model, 'username'),
                ));
                ?>

                <div class="row">
                    <?php echo $form->textField($model, 'username', array('placeholder' => Yii::t('register', 'email'))); ?>
                    <?php echo $form->error($model, 'username'); ?>
                </div>

                <div class="row">
                    <?php echo $form->passwordField($model, 'password', array('placeholder' => Yii::t('register', 'password'), 'autocomplete' => 'off', 'value' => '')); ?>
                    <?php echo $form->error($model, 'password'); ?>
                </div>

                <?php if ($model->scenario == 'withCaptcha' && CCaptcha::checkRequirements()): ?>
                    <div class="row">
                        <?php
                        $this->widget('CCaptcha', array(
                            'buttonType' => 'link',
                            'clickableImage' => true,
                            'showRefreshButton' => false,
                                )
                        );
                        ?>
                    </div>
                    <p><?= Yii::t('contactus', 'chage_image') ?></p>
                    <div class="row">
                        <?php echo $form->textField($model, 'verify_code', array('placeholder' => Yii::t('contactus', 'verify_code'))); ?>
                        <?php echo $form->error($model, 'verify_code'); ?>
                    </div>
                <?php endif; ?>

                <div class="row rememberMe">
                    <?php echo $form->checkBox($model, 'rememberMe', array('class' => 'js-switch')) . " " . Yii::t('login', 'remember') ?>
                    <?php echo $form->error($model, 'rememberMe'); ?>
                </div>
                <script type="text/javascript">
                    var elem = document.querySelector('.js-switch');
                    var init = new Switchery(elem);
                </script>
                <br />

                <div class="row buttons">
                    <?php echo CHtml::tag('button', array('class' => 'btn', 'type' => 'submit'), Yii::t('login', 'login')); ?>
                </div>

                <?php echo CHtml::link(Yii::t('register', 'register'), array('register/index')); ?><br/>
                <?php echo CHtml::link(Yii::t('login', 'forget_password'), array('forgetpass/index')); ?>

                <?php $this->endWidget(); ?>
            </div><!-- form -->
        </div>
    </div>
</div>